<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tab切换</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }

        body{
            width: 100vw;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        dl{
            width: 300px;
            height: 600px;
        }

        dt{
            width: 100%;
            height: 80px;
            background: orange;
            display: flex;
            justify-content: center;
            align-items: center;
            border-bottom: 1px solid #333;
        }

        dd{
            width: 100%;
            height: 150px;
            background: grey;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        [hidden = "hidden"]{
            display: none;
        }
    </style>
</head>
<body>
    <dl>
        <dt>xiasnn</dt>
        <dd>1</dd>
        <dt>houdunren</dt>
        <dd hidden="hidden">2</dd>
    </dl>
    <script>
        // 不使用call
        // document.querySelectorAll('dt').forEach((dt,idx) => {
        //     dt.addEventListener('click',() => {
        //         let dds = document.querySelectorAll('dd');
        //         dds.forEach(dd => dd.setAttribute('hidden','hidden'));
        //         dds[idx].removeAttribute('hidden');
        //     });
        // });



        // 使用call
        function tab(idx){
            let dds = document.querySelectorAll('dd');
            dds.forEach(dd => dd.setAttribute('hidden','hidden'));
            dds[idx].removeAttribute('hidden');
        }

        document.querySelectorAll('dt').forEach((dt,idx) => {
            dt.addEventListener('click',() => {
                // call如果不需要传this，就写null
                tab.call(null,idx);
            });
        });
    </script>
</body>
</html>